package com.atguigu.dga.governance.assessor.spec;

import com.atguigu.dga.governance.assessor.Assessor;
import com.atguigu.dga.governance.bean.AssessParam;
import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import com.atguigu.dga.governance.bean.GovernanceMetric;
import com.atguigu.dga.meta.bean.TableMetaInfo;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component("IS_TABLE_NAME_STANDARD")
public class IsTableNameStandardAssessor extends Assessor {


    private   Pattern odsPattern = Pattern.compile("^ods_\\w+_(inc|full)$");
    private   Pattern dimPattern = Pattern.compile("^dim_\\w+_(zip|full)$");
    private   Pattern dwdPattern = Pattern.compile("^dwd_\\w+_\\w+_(inc|full)$");
    private   Pattern dwsPattern = Pattern.compile("^dws_\\w+_\\w+_\\w+_(1d|nd|td)$");
    private   Pattern adsPattern = Pattern.compile("^ads_\\w+$");
    private   Pattern dmPattern = Pattern.compile("^dm_\\w+$");  //data macket 数据集市

    @Override
    public void checkProblem(AssessParam assessParam, GovernanceAssessDetail governanceAssessDetail) {
        String tableName = assessParam.getTableMetaInfo().getTableName();
        String dwLevel = assessParam.getTableMetaInfo().getTableMetaInfoExtra().getDwLevel();

        if(dwLevel.equals("OTHER")){
            governanceAssessDetail.setAssessProblem("未纳入分层");
            governanceAssessDetail.setAssessScore(BigDecimal.valueOf(5));
            return;
        }

        boolean isStandard = true;
        if( dwLevel.equals("ODS")&& !odsPattern.matcher(tableName).matches()){
            isStandard=false;
        } else if (dwLevel.equals("DIM")&& !dimPattern.matcher(tableName).matches()) {
            isStandard=false;
        } else if (dwLevel.equals("DWD")&& !dwdPattern.matcher(tableName).matches()) {
            isStandard=false;
        } else if (dwLevel.equals("DWS")&& !dwsPattern.matcher(tableName).matches()) {
            isStandard=false;
        } else if (dwLevel.equals("ADS")&& !adsPattern.matcher(tableName).matches()) {
            isStandard=false;
        } else if (dwLevel.equals("DM")&& !dmPattern.matcher(tableName).matches()) {
            isStandard=false;
        }
        if(!isStandard){
            governanceAssessDetail.setAssessProblem("表名不符合规范！");
            governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
        }

    }


    public static void main(String[] args) {
        //    \w{2,16}@\w{2,8}\.(com|org|cn)
        String email ="windyzj@atguigu.com";
        Pattern emailPattern = Pattern.compile("^\\w{2,16}@\\w{2,8}\\.(com|org|cn)$");

        Matcher matcher = emailPattern.matcher(email);
        if(matcher.matches()){
            System.out.println(" 邮箱合格！");
        }else{
            System.out.println(" 邮箱不合格 !" );
        }



    }
}
